import { View, Text, Image } from '@tarojs/components'
import { memo } from 'react'
import { useState, useEffect } from 'react'

import './index.scss'

//  引入图片
import network from '@/assets/images/empty/network.png'
import server from '@/assets/images/empty/404.png'
import order from '@/assets/images/empty/order.png'
import search from '@/assets/images/empty/search.png'

interface BtPageStatusProps {
    total: number
    text?: string
    status: 'empty' | 'network' | 'server'  | 'order' |  'search' | 'point'
}
function BtPageStatus({
    status,
    text,
    total
}: BtPageStatusProps) {
    // 根据状态引入对应图
    const [statusMap, setStatusMap] = useState({
        map: order,
        text: '暂无订单'
    })
    // 根据total判断是否显示
    const [isShow, setIsShow] = useState(false)
    useEffect(() => {
        //   状态一共六种: 暂无活动\暂无订单\网络故障\服务器异常\暂无商品\暂无数据\暂无搜索结果\暂无积分流水
        const statusMap = {
            'empty': {
                map: order,
                text: '暂无订单'
            },
            'network': {
                map: network,
                text: '网络故障'
            },
            'server': {
                map: server,
                text: '服务器异常'
            },


            'search': {
                map: search,
                text: '暂无搜索结果'
            },
            'order': {
                map: order,
                text: '暂无订单'
            },
            'point': {
                map: order,
                text: '暂无积分流水'
            }
        }
        setStatusMap(statusMap[status])
        if (total === 0) {
            setIsShow(true)
        } else {
            setIsShow(false)
        }
    }, [status, total])

    return (
        <View className="bt-page-status">
            {isShow &&
                <View className="bt-page-status-empty">
                    <Image className="bt-page-status-image" src={statusMap.map} />
                    <Text className="bt-page-status-text">{text || statusMap.text}</Text>
                </View>
            }
        </View>
    )
}

export default memo(BtPageStatus)
